#include "loadcontainer.h"

CLoadContainer::CLoadContainer(LPCSTR name)
{
    m_appclsid = StringToGUID(name);
}

CLoadContainer::~CLoadContainer()
{
}
int CLoadContainer::Init(LPSTRING path, LPCSTR code)
{
    int rc = S_SUCCESS;

    SafePStringPtr containerpath;
    containerpath.ptr = path;
    containerpath.len = tstring_strlen(path);

    SafeStringPtr containercode;
    containercode.ptr = code;
    containercode.len = s_strlen(code);

    logi("LoadContainer");
    m_Container.LoadContainer(&containerpath);
    rc_error(rc == S_SUCCESS, E_FAIL);

    logi("CreateContainer");
    m_Container.CreateContainer(m_appclsid, &containerpath, &containercode);
    rc_error(rc == S_SUCCESS, E_FAIL);

    logi("InitContainer");
    m_Container.InitContainer(m_appclsid, NULL, NULL, 0);
    rc_error(rc == S_SUCCESS, E_FAIL);

    return S_SUCCESS;
}

int CLoadContainer::UnInit()
{
    logi("UnInitContainer");
    return m_Container.UnInitContainer(m_appclsid);
}

int CLoadContainer::Start(UINT type)
{
    logi("StartContainer");
    return m_Container.StartContainer(m_appclsid, 0);
}

int CLoadContainer::Stop(UINT type, UINT exit)
{
    logi("StopContainer");
    return m_Container.StopContainer(m_appclsid, 0, OBJECT_RUN_RET_SUCCESS);
}
int CLoadContainer::Exit(UINT exit)
{
    logi("ExitContainer");
    return m_Container.ExitContainer(m_appclsid, exit);
}